package com.lc.afbx.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiCardType;
import com.lc.afbx.conn.GetApiProfrssion;
import com.lc.afbx.conn.GetApiRelationship;
import com.lc.afbx.conn.GetApiShouXianDetail;
import com.lc.afbx.conn.PostIDCard;
import com.lc.afbx.dialog.AlertDialog;
import com.lc.afbx.dialog.PictureDialog;
import com.lc.afbx.dialog.ShowPicDialog;
import com.lc.afbx.util.Base64Encoder;
import com.lc.afbx.util.DateTimePickDialogBefore;
import com.lc.afbx.util.DateTimePickDialogUtil;
import com.lc.afbx.util.MEditTextListener;
import com.lc.afbx.util.MyToast;
import com.lc.afbx.util.PictureUtil;
import com.lc.afbx.util.PrefrenceConfig;
import com.lc.afbx.util.Validator;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilLog;
import com.zcx.helper.util.UtilMD5;
import com.zcx.helper.util.UtilToast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/7/7.
 */
public class LifeInsuranceFillInfoActivity extends BasePictureActivity implements View.OnClickListener {

    private TextView startTime;
    private EditText touBaoRenName;

    //受益人性别
    private ImageView imgNanShouYi;
    private ImageView imgWomenShouYi;
    //保险份数
    private TextView count;


    private EditText toubaoren_sex_shouxian_et;//性别
    private EditText country;//国籍
    private EditText hasWife;//婚姻状况
    private TextView cardType;//证件类型
    private EditText cardNum;//证件号码
    private TextView birthday;//出生日期
    private EditText touBaoRenage;   //投保人年龄
    private EditText workPlace;//工作单位
    private EditText income;    //年收入
    private TextView job;       //职业
    private EditText phoneNum; //投保人手机号
    private EditText homeTel;   //家庭电话
    private EditText workTel;  //工作电话
    private EditText reCallFirst;//首选回访电话
    private EditText address;//联系地址
    private EditText postCode;//邮编
    private EditText homeAddress;//家庭地址
    private EditText homePostCode;//家庭地址 的邮编
    private EditText mEmail;//邮箱
    private TextView yuBeiBaoRen;//与被保险人关系
    private EditText shouYiRenName;//身故保险金 受益人名字
    private TextView shouYiRenBirthday_ywx;//身故保险金 受益人生日
    private TextView shiBeiBaoRenDe;//是被保险人的
    private TextView shouYiRenCardType; //受益人证件类型
    private EditText shouYiRenidCardNum;//受益人证件号码
    private EditText shouYiBiLv; //受益比率  TODO 这个有问题  应该是手填的还不是 不清楚
    private TextView shouYiShunXu;//受益顺序
    private TextView xianZhongName; //险种名称
    private TextView durationTime;  //保险期限
    private TextView payType;   //缴费方式
    private TextView payCount;  //缴费期限   一共多少期
    private TextView oncePay;   //一期缴费多少

    private int i;
    private Map<Integer, String> picMap;

    private List<String> payTypeList;
    private List<String> relationList;

    private PictureDialog pictureDialog;
    private Bundle bundle;
    private GetApiShouXianDetail.Data data;

    ///others
    private EditText name_other;
    private EditText other_sex_shouxian_et;
    private EditText country_other;
    private EditText hasWife_other;
    private TextView cardType_other;
    private TextView birthday_other;
    private EditText cardNum_other;
    private EditText age_other;
    private EditText workPlace_other;
    private EditText income_other;
    private TextView job_other;
    private EditText phoneNum_other;
    private EditText homeTel_other;
    private EditText workTel_other;
    private EditText reCallFirst_other;
    private EditText address_other;
    private EditText postCode_other;
    private EditText homeAddress_other;
    private EditText homePostCode_other;
    private EditText email_other;


    private PostIDCard postIDCard = new PostIDCard(new AsyCallBack<PostIDCard.IdCardInfoEntity>() {
        @Override
        public void onSuccess(String toast, int type, PostIDCard.IdCardInfoEntity idCardInfoEntity) throws Exception {

//            String code, result, name, gender, people, byear, bmonth, bday, address, idnumber, authority, validdate, age;


            if (type == 1) {

                name_other.setText(idCardInfoEntity.name);
                other_sex_shouxian_et.setText(idCardInfoEntity.gender);
                country_other.setText("中国");
                age_other.setText(idCardInfoEntity.age);
                birthday_other.setText(idCardInfoEntity.byear + "-" + idCardInfoEntity.bmonth + "-" + idCardInfoEntity.bday);
                cardType_other.setText("身份证");
                cardNum_other.setText(idCardInfoEntity.idnumber);
                homeAddress_other.setText(idCardInfoEntity.address);

            } else {

                touBaoRenName.setText(idCardInfoEntity.name);
                toubaoren_sex_shouxian_et.setText(idCardInfoEntity.gender);
                country.setText("中国");
                touBaoRenage.setText(idCardInfoEntity.age);
                birthday.setText(idCardInfoEntity.byear + "-" + idCardInfoEntity.bmonth + "-" + idCardInfoEntity.bday);
                cardType.setText("身份证");
                cardNum.setText(idCardInfoEntity.idnumber);
                homeAddress.setText(idCardInfoEntity.address);
            }


        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            MyToast.showToast(toast, context);
        }
    });


    private List<String> jobList;
    //职业列表接口
    private GetApiProfrssion getApiProfrssion = new GetApiProfrssion(new AsyCallBack<GetApiProfrssion.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiProfrssion.Info info) throws Exception {

            jobList = new ArrayList<>();

            for (int i = 0; i < info.dataList.size(); i++) {
                jobList.add(info.dataList.get(i).title);
            }
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }
    });

    private List<String> cardTypeList;
    //证件类型接口
    private GetApiCardType getApiCardType = new GetApiCardType(new AsyCallBack<GetApiCardType.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiCardType.Info info) throws Exception {

            cardTypeList = new ArrayList<>();
            for (int i = 0; i < info.dataList.size(); i++) {
                cardTypeList.add(info.dataList.get(i).title);
            }
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }
    });

    private List<String> relationshipList;//是被保险人的  关系list
    //是被保险人的  关系列表 请求接口
    private GetApiRelationship getApiRelationship = new GetApiRelationship(new AsyCallBack<GetApiRelationship.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiRelationship.Info info) throws Exception {

            relationshipList = new ArrayList<>();

            for (int i = 0; i < info.dataList.size(); i++) {
                relationshipList.add(info.dataList.get(i).relationship);
            }
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }
    });

    private LinearLayout shouYiRenLayout;
    private ImageView img_addView;
    private View dathInfo_layout;

    //填加身故受益人信息的view
    private ImageView manImg_newView;
    private ImageView womenImg_newView;


    private Map<String, View> holderMap;

    private String payTypeValue;

    private ImageView life_show_idcard_iv;
    private ImageView life_show_people_iv;
    private ImageView life_show_idcard_other_iv;
    private ImageView life_show_people_other_iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shouye_shouxian_tianxiexinxi);

        bundle = getIntent().getExtras();

        initView();

        setListener();

        picMap = new HashMap<>();

        getApiProfrssion.execute(this);
        getApiCardType.execute(this);
        getApiRelationship.execute(this);

        life_show_idcard_iv = ((ImageView) findViewById(R.id.life_show_idcard_iv));
        life_show_people_iv = ((ImageView) findViewById(R.id.life_show_people_iv));
        life_show_idcard_other_iv = ((ImageView) findViewById(R.id.life_show_idcard_other_iv));
        life_show_people_other_iv = ((ImageView) findViewById(R.id.life_show_people_other_iv));
        life_show_idcard_iv.setOnClickListener(this);
        life_show_people_iv.setOnClickListener(this);
        life_show_idcard_other_iv.setOnClickListener(this);
        life_show_people_other_iv.setOnClickListener(this);

    }

    private void setListener() {
        startTime.setOnClickListener(this);
        payType.setOnClickListener(this);
        birthday.setOnClickListener(this);
        yuBeiBaoRen.setOnClickListener(this);
        //其他被保险人 生日
        birthday_other.setOnClickListener(this);

        shiBeiBaoRenDe.setOnClickListener(this);
        cardType.setOnClickListener(this);
        job.setOnClickListener(this);
        shouYiRenCardType.setOnClickListener(this);
        cardType_other.setOnClickListener(this);
        job_other.setOnClickListener(this);
        img_addView.setOnClickListener(this);
        shouYiRenBirthday_ywx.setOnClickListener(this);


        //投保人
        touBaoRenName.addTextChangedListener(new MEditTextListener(context, 16, touBaoRenName));
        country.addTextChangedListener(new MEditTextListener(context, 16, country));
        hasWife.addTextChangedListener(new MEditTextListener(context, 6, hasWife));
        cardNum.addTextChangedListener(new MEditTextListener(context, 18, cardNum));
        touBaoRenage.addTextChangedListener(new MEditTextListener(context, 2, touBaoRenage));
        workPlace.addTextChangedListener(new MEditTextListener(context, 30, workPlace));
        income.addTextChangedListener(new MEditTextListener(context, 8, income));
        phoneNum.addTextChangedListener(new MEditTextListener(context, 11, phoneNum));
        homeTel.addTextChangedListener(new MEditTextListener(context, 12, homeTel));
        workTel.addTextChangedListener(new MEditTextListener(context, 12, workTel));
        reCallFirst.addTextChangedListener(new MEditTextListener(context, 12, reCallFirst));
        address.addTextChangedListener(new MEditTextListener(context, 30, address));
        postCode.addTextChangedListener(new MEditTextListener(context, 6, postCode));
        homeAddress.addTextChangedListener(new MEditTextListener(context, 30, homeAddress));
        homePostCode.addTextChangedListener(new MEditTextListener(context, 6, homePostCode));
        mEmail.addTextChangedListener(new MEditTextListener(context, 30, mEmail));
        shouYiRenName.addTextChangedListener(new MEditTextListener(context, 16, shouYiRenName));
        shouYiRenidCardNum.addTextChangedListener(new MEditTextListener(context, 18, shouYiRenidCardNum));
        shouYiBiLv.addTextChangedListener(new MEditTextListener(context, 5, shouYiBiLv));

        //其他被保险人

        name_other.addTextChangedListener(new MEditTextListener(context, 16, name_other));
        country_other.addTextChangedListener(new MEditTextListener(context, 16, country_other));
        hasWife_other.addTextChangedListener(new MEditTextListener(context, 6, hasWife_other));
        cardNum_other.addTextChangedListener(new MEditTextListener(context, 18, cardNum_other));
        age_other.addTextChangedListener(new MEditTextListener(context, 2, age_other));
        workPlace_other.addTextChangedListener(new MEditTextListener(context, 30, workPlace_other));
        income_other.addTextChangedListener(new MEditTextListener(context, 8, income_other));

        phoneNum_other.addTextChangedListener(new MEditTextListener(context, 11, phoneNum_other));
        homeTel_other.addTextChangedListener(new MEditTextListener(context, 12, homeTel_other));
        workTel_other.addTextChangedListener(new MEditTextListener(context, 12, workTel_other));
        reCallFirst_other.addTextChangedListener(new MEditTextListener(context, 12, reCallFirst_other));
        address_other.addTextChangedListener(new MEditTextListener(context, 30, address_other));
        postCode_other.addTextChangedListener(new MEditTextListener(context, 6, postCode_other));
        homeAddress_other.addTextChangedListener(new MEditTextListener(context, 30, homeAddress_other));
        homePostCode_other.addTextChangedListener(new MEditTextListener(context, 6, homePostCode_other));
        email_other.addTextChangedListener(new MEditTextListener(context, 30, email_other));

    }

    private void initView() {

        holderMap = new HashMap<>();

        payTypeList = new ArrayList<>();
        payTypeList.add("分期缴付");
        payTypeList.add("趸交");

        relationList = new ArrayList<>();
        relationList.add("本人");
        relationList.add("其他被保险人");

        //这是对话框啊
        pictureDialog = new PictureDialog(this) {
            @Override
            protected void onCamera() {
                startCamera(null);
            }

            @Override
            protected void onAlbum() {
                startAlbum(null);
            }
        };

        findViewById(R.id.back).setOnClickListener(this);
        findViewById(R.id.btn_next_ywx).setOnClickListener(this);

        //受益人性别 layout
        findViewById(R.id.sexManLayout_ywx).setOnClickListener(this);
        findViewById(R.id.sexWomenLayout_ywx).setOnClickListener(this);
        //加减
        findViewById(R.id.imgJian_ywx).setOnClickListener(this);
        findViewById(R.id.imgJia_ywx).setOnClickListener(this);
        //上传身份证
        findViewById(R.id.idCard_submit_ywx).setOnClickListener(this);
        findViewById(R.id.peoplePicSubmit_ywx).setOnClickListener(this);

        imgNanShouYi = ((ImageView) findViewById(R.id.manImg_ywx));
        imgWomenShouYi = ((ImageView) findViewById(R.id.womenLayoutImg_ywx));
        count = ((TextView) findViewById(R.id.count_ywx));

        startTime = ((TextView) findViewById(R.id.startTime_ywx));
        cardType = ((TextView) findViewById(R.id.cardType_ywx));
        birthday = ((TextView) findViewById(R.id.birthday_ywx));
        job = ((TextView) findViewById(R.id.job_ywx));
        yuBeiBaoRen = ((TextView) findViewById(R.id.yuBeiBaoRen_ywx));
        shiBeiBaoRenDe = ((TextView) findViewById(R.id.shiBeiBaoRenDe_ywx));
        shouYiRenCardType = ((TextView) findViewById(R.id.shouYiRenCardtype_ywx));
        shouYiBiLv = ((EditText) findViewById(R.id.shouYiBiLv_ywx));
        shouYiShunXu = ((TextView) findViewById(R.id.shouYiShunXu_ywx));
        xianZhongName = ((TextView) findViewById(R.id.xianZhongName_ywx));
        durationTime = ((TextView) findViewById(R.id.durationTime_ywx));
        payType = ((TextView) findViewById(R.id.payType_ywx));
        payCount = ((TextView) findViewById(R.id.payCount_ywx));
        oncePay = ((TextView) findViewById(R.id.oncePay_ywx));


        touBaoRenName = ((EditText) findViewById(R.id.name_ywx));
        toubaoren_sex_shouxian_et = ((EditText) findViewById(R.id.toubaoren_sex_shouxian_et));
        country = ((EditText) findViewById(R.id.country_ywx));
        hasWife = ((EditText) findViewById(R.id.hasWife_ywx));
        cardNum = ((EditText) findViewById(R.id.cardNum_ywx));
        touBaoRenage = ((EditText) findViewById(R.id.age_ywx));
        workPlace = ((EditText) findViewById(R.id.workPlace_ywx));
        income = ((EditText) findViewById(R.id.income_ywx));
        phoneNum = ((EditText) findViewById(R.id.phoneNum_ywx));
        homeTel = ((EditText) findViewById(R.id.homeTel_ywx));
        workTel = ((EditText) findViewById(R.id.workTel_ywx));
        reCallFirst = ((EditText) findViewById(R.id.reCallFirst_ywx));
        address = ((EditText) findViewById(R.id.address_ywx));
        postCode = ((EditText) findViewById(R.id.postCode_ywx));
        homeAddress = ((EditText) findViewById(R.id.homeAddress_ywx));
        homePostCode = ((EditText) findViewById(R.id.homePostCode_ywx));
        mEmail = ((EditText) findViewById(R.id.email_ywx));
        shouYiRenBirthday_ywx = ((TextView) findViewById(R.id.shouYiRenBirthday_ywx));
        shouYiRenName = ((EditText) findViewById(R.id.shouYiRenName_ywx));
        shouYiRenidCardNum = ((EditText) findViewById(R.id.shouYiRenidCardNum_ywx));

        //险种名称  持续时间  从上页面的bunlde获值
        data = (GetApiShouXianDetail.Data) bundle.getSerializable(PrefrenceConfig.BUNDLE_TAG);
        xianZhongName.setText(data.title);
        durationTime.setText(data.deadline + "个月");

        //设置保费
        ((TextView) findViewById(R.id.baofei)).setText(new DecimalFormat("0.00").format(Float.valueOf(data.premium)));

        //缴费类型 默认选趸交
        payType.setText(payTypeList.get(1));
        payTypeValue = "1";
//        payType.setTag("2");
        // 显示保费 隐藏分起的布局
        findViewById(R.id.rlayout_dunJiao_show).setVisibility(View.VISIBLE);
        findViewById(R.id.lLayout_fenqi_show).setVisibility(View.GONE);

        //与被保险人关系  默认选本人 隐藏下面填写信息的布局
        yuBeiBaoRen.setText(relationList.get(0));
        yuBeiBaoRen.setTag(String.valueOf(1));
        findViewById(R.id.lLayout_otherInfo).setVisibility(View.GONE);


        //受益人性别
        imgNanShouYi.setImageResource(R.mipmap.nv);
        imgWomenShouYi.setImageResource(R.mipmap.nan);
        imgNanShouYi.setTag(true);
        imgWomenShouYi.setTag(false);

        ///////////////下面是其他被保险人信息///////////////


        name_other = ((EditText) findViewById(R.id.name_ywx2));

        other_sex_shouxian_et = ((EditText) findViewById(R.id.other_sex_shouxian_et));
        country_other = ((EditText) findViewById(R.id.country_ywx2));
        hasWife_other = ((EditText) findViewById(R.id.hasWife_ywx2));
        cardType_other = ((TextView) findViewById(R.id.cardType_ywx2));
        birthday_other = ((TextView) findViewById(R.id.birthday_ywx2));
        cardNum_other = ((EditText) findViewById(R.id.cardNum_ywx2));
        age_other = ((EditText) findViewById(R.id.age_ywx2));
        workPlace_other = ((EditText) findViewById(R.id.workPlace_ywx2));
        income_other = ((EditText) findViewById(R.id.income_ywx2));
        job_other = ((TextView) findViewById(R.id.job_ywx2));
        phoneNum_other = ((EditText) findViewById(R.id.phoneNum_ywx2));
        homeTel_other = ((EditText) findViewById(R.id.homeTel_ywx2));
        workTel_other = ((EditText) findViewById(R.id.workTel_ywx2));
        reCallFirst_other = ((EditText) findViewById(R.id.reCallFirst_ywx2));
        address_other = ((EditText) findViewById(R.id.address_ywx2));
        postCode_other = ((EditText) findViewById(R.id.postCode_ywx2));
        homeAddress_other = ((EditText) findViewById(R.id.homeAddress_ywx2));
        homePostCode_other = ((EditText) findViewById(R.id.homePostCode_ywx2));
        email_other = ((EditText) findViewById(R.id.email_ywx2));


        findViewById(R.id.peoplePicSubmit_ywx2).setOnClickListener(this);
        findViewById(R.id.idCard_submit_ywx2).setOnClickListener(this);


        //动态添加的  身故保险金受益人view
        shouYiRenLayout = ((LinearLayout) findViewById(R.id.shouYiRenLayout));
        img_addView = ((ImageView) findViewById(R.id.img_addView));

        dathInfo_layout = findViewById(R.id.dathInfo_layout);

        holderMap.put("0", dathInfo_layout);

    }

    @Override
    public void onClick(View view) {
        //计算买的份数
        int aa = Integer.parseInt(count.getText().toString());
        //
        DateTimePickDialogUtil dialogUtil = null;

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.life_show_idcard_iv:

                new ShowPicDialog(this, picMap.get(1)).show();

                return;

            case R.id.life_show_people_iv:

                new ShowPicDialog(this, picMap.get(2)).show();

                return;

            case R.id.life_show_idcard_other_iv:

                new ShowPicDialog(this, picMap.get(3)).show();

                return;

            case R.id.life_show_people_other_iv:

                new ShowPicDialog(this, picMap.get(4)).show();

                return;

            case R.id.shouYiRenBirthday_ywx:

                dialogUtil = new DateTimePickDialogUtil(this, null);
                dialogUtil.dateTimePicKDialog(shouYiRenBirthday_ywx);

                return;

            case R.id.img_addView:

                initAddedview();
                MyToast.showToast("添加受益人成功", context);
                return;

            case R.id.job_ywx2:
                view.setTag(8);
                showPopupWindow(view, -1);
                return;

            case R.id.cardType_ywx2:
                view.setTag(7);
                showPopupWindow(view, -1);
                return;

            case R.id.shouYiRenCardtype_ywx:
                view.setTag(6);
                showPopupWindow(view, -1);
                return;

            case R.id.job_ywx:
                view.setTag(5);
                showPopupWindow(view, -1);
                return;

            case R.id.cardType_ywx:
                view.setTag(4);
                showPopupWindow(view, -1);
                return;

            case R.id.shiBeiBaoRenDe_ywx:
                view.setTag(3);
                showPopupWindow(view, -1);
                return;

            case R.id.birthday_ywx2:
                dialogUtil = new DateTimePickDialogUtil(this, null);
                dialogUtil.dateTimePicKDialog(birthday_other);
                return;


            //其他被保险人的  投保人照片
            case R.id.peoplePicSubmit_ywx2:
                i = 4;
                pictureDialog.show();
                return;

            //其他被保险人的  身份证照片
            case R.id.idCard_submit_ywx2:
                i = 3;
                pictureDialog.show();
                return;

            case R.id.startTime_ywx:
                DateTimePickDialogBefore timePickDialogBefore = new DateTimePickDialogBefore(context);
                timePickDialogBefore.dateTimePicKDialog(startTime);
                return;

            case R.id.birthday_ywx:
                dialogUtil = new DateTimePickDialogUtil(this, null);
                dialogUtil.dateTimePicKDialog(birthday);
                return;
            //缴费方式
            case R.id.payType_ywx:
                view.setTag(1);
                showPopupWindow(view, -1);
                return;
            //与被保险人关系
            case R.id.yuBeiBaoRen_ywx:
                view.setTag(2);
                showPopupWindow(view, -1);
                return;
            //上传身份证
            case R.id.idCard_submit_ywx:
                i = 1;
                pictureDialog.show();
                return;
            //上传投保人照片
            case R.id.peoplePicSubmit_ywx:
                i = 2;
                pictureDialog.show();
                return;
            //加减  按钮
            case R.id.imgJian_ywx:
                if (aa == 1) {
                    UtilToast.show(this, "最少买一份");
                } else {
                    count.setText(String.valueOf(aa - 1));

                    ((TextView) findViewById(R.id.baofei)).setText(new DecimalFormat(".00")
                            .format(Float.parseFloat(data.premium) * Integer.parseInt(count.getText().toString())));//设置保费

                }
                return;
            //加减  按钮
            case R.id.imgJia_ywx:
                count.setText(String.valueOf(aa + 1));

                ((TextView) findViewById(R.id.baofei)).setText(new DecimalFormat(".00")
                        .format(Float.parseFloat(data.premium) * Integer.parseInt(count.getText().toString())));//设置保费
                return;


            //受益人性别的点击
            case R.id.sexManLayout_ywx:
                imgNanShouYi.setImageResource(R.mipmap.nv);
                imgWomenShouYi.setImageResource(R.mipmap.nan);
                imgNanShouYi.setTag(true);
                imgWomenShouYi.setTag(false);
                return;
            case R.id.sexWomenLayout_ywx:
                imgNanShouYi.setImageResource(R.mipmap.nan);
                imgWomenShouYi.setImageResource(R.mipmap.nv);
                imgNanShouYi.setTag(false);
                imgWomenShouYi.setTag(true);
                return;
            //下一步按钮
            case R.id.btn_next_ywx:

                Intent intent = new Intent(this, LifeInsuranceInsureActivity.class);
                //bundle 从上个页面来的
                Bundle bundle = getIntent().getExtras();

                String name = touBaoRenName.getText().toString();//姓名
                String touBaoRenSex = toubaoren_sex_shouxian_et.getText().toString();                            //性别

                String nationality = country.getText().toString();//国籍
                String marriage = hasWife.getText().toString();//婚姻状况
                String papers_type = cardType.getText().toString();//证件类型

                String idnum = cardNum.getText().toString();//证件号码
                String birth = birthday.getText().toString();//出生日期
//                String id_url = picMap.get(1);          //上传身份证件
//                String self_url = picMap.get(2);        //上传投保人照片
                String age = touBaoRenage.getText().toString();//年龄

                String work_unit = workPlace.getText().toString();//工作单位
                String annual_income = income.getText().toString();//年收入
                String profession = job.getText().toString();//职业
                String cellphone = phoneNum.getText().toString();//投保人手机号
                String telephone = homeTel.getText().toString();//家庭电话

                String office_phone = workTel.getText().toString();//办公电话
                String first_phone = reCallFirst.getText().toString();//首选回访电话
                String contact_addr = address.getText().toString();//联系地址
                String c_postcode = postCode.getText().toString();//邮编
                String home_addr = homeAddress.getText().toString();//家庭地址

                String h_postcode = homePostCode.getText().toString();//家庭地址 的邮编
                String email = mEmail.getText().toString();//家庭地址


                //身故受益人信息
                String name_shouYiRen = shouYiRenName.getText().toString();//身故保险金 受益人名字
                String birthday_shouYiRen = shouYiRenBirthday_ywx.getText().toString();//身故保险金 受益人生日
                String sex;
                if ((boolean) imgNanShouYi.getTag()) {
                    sex = "男";
                } else {
                    sex = "女";
                }
                String relation = shiBeiBaoRenDe.getText().toString();//是被保险人的
                String papers_type_shouYiRen = shouYiRenCardType.getText().toString();//受益人证件类型
                String number = shouYiRenidCardNum.getText().toString();//受益人证件号码
                String benefit_ratio = shouYiBiLv.getText().toString();//受益比率

                String benefit_order = shouYiShunXu.getText().toString();//受益顺序

                ////最下面几个变量////////////////////////////
                String insurance_type = xianZhongName.getText().toString();//险种名称
                String copies = count.getText().toString();//份数
                String premium = ((TextView) findViewById(R.id.baofei)).getText().toString();//保费
                String payment_way = payTypeValue;//缴费方式

                String starttime = startTime.getText().toString();//起保时间
                String payment_is = payCount.getText().toString();//缴费期限 一共多少期
                String time_limit = durationTime.getText().toString();//保险期限


                //TODO 与被保险人关系 这单独交
                String relation_yuBeiBao = (String) yuBeiBaoRen.getTag();

                //其他被保险人信息在这里
                if (relation_yuBeiBao.equals("2")) {


                    String name_str = name_other.getText().toString();
                    String country_str = country_other.getText().toString();
                    String hasWife_str = hasWife_other.getText().toString();
                    String cardType_str = cardType_other.getText().toString();
                    String birthday_str = birthday_other.getText().toString();

                    String cardNum_str = cardNum_other.getText().toString();
                    String age_str = age_other.getText().toString();
                    String workPlace_str = workPlace_other.getText().toString();
                    String income_str = income_other.getText().toString();
                    String job_str = job_other.getText().toString();

                    String phoneNum_str = phoneNum_other.getText().toString();
                    String homeTel_str = homeTel_other.getText().toString();
                    String workTel_str = workTel_other.getText().toString();
                    String reCallFirst_str = reCallFirst_other.getText().toString();
                    String address_str = address_other.getText().toString();

                    String postCode_str = postCode_other.getText().toString();
                    String homeAddress_str = homeAddress_other.getText().toString();
                    String homePostCode_str = homePostCode_other.getText().toString();
                    String email_str = email_other.getText().toString();

                    String sex_str = other_sex_shouxian_et.getText().toString();

//                    String idCardUrl = picMap.get(3);
//                    String peopleUrl = picMap.get(4);

                    JSONObject o = new JSONObject(); //其他被保险人信息

                    try {

                        if (TextUtils.isEmpty(picMap.get(3))) {
                            UtilToast.show(context, "请上传其他投保人身份证照片");
                            return;
                        } else if (TextUtils.isEmpty(name_str)) {
                            UtilToast.show(context, "投保人姓名不能为空");
                            return;
                        } else if (TextUtils.isEmpty(sex_str)) {
                            UtilToast.show(context, "性别不能为空");
                            return;
                        } else if (TextUtils.isEmpty(country_str)) {
                            UtilToast.show(context, "国籍不能为空");
                            return;
                        } else if (TextUtils.isEmpty(age_str)) {
                            UtilToast.show(context, "年龄不能为空");
                            return;
                        } else if (TextUtils.isEmpty(birthday_str)) {
                            UtilToast.show(context, "出生日期不能为空");
                            return;
                        } else if (TextUtils.isEmpty(cardType_str)) {
                            UtilToast.show(context, "请选择证件类型");
                            return;
                        } else if (TextUtils.isEmpty(cardNum_str)) {
                            UtilToast.show(context, "证件号码不能为空");
                            return;
                        } else if (!Validator.isIDCard(cardNum_str)) {
                            MyToast.showToast("证件号码不正确", context);
                            return;
                        } else if (TextUtils.isEmpty(homeAddress_str)) {
                            UtilToast.show(context, "家庭地址不能为空");
                            return;
                        } else if (TextUtils.isEmpty(homePostCode_str)) {
                            UtilToast.show(context, "邮编不能为空");
                            return;
                        } else if (!Validator.isPostCode(homePostCode_str)) {
                            MyToast.showToast("家庭地址邮编格式不正确", context);
                            return;
                        } else if (TextUtils.isEmpty(hasWife_str)) {
                            UtilToast.show(context, "婚姻状况不能为空");
                            return;
                        } else if (TextUtils.isEmpty(picMap.get(4))) {
                            UtilToast.show(context, "请上传其他投保人照片");
                            return;
                        } else if (TextUtils.isEmpty(workPlace_str)) {
                            UtilToast.show(context, "工作单位不能为空");
                            return;
                        } else if (TextUtils.isEmpty(income_str)) {
                            UtilToast.show(context, "年收入不能为空");
                            return;
                        } else if (TextUtils.isEmpty(job_str)) {
                            UtilToast.show(context, "请选择职业");
                            return;
                        } else if (TextUtils.isEmpty(phoneNum_str)) {
                            UtilToast.show(context, "手机号码不能为空");
                            return;
                        } else if (!Validator.isMobile(phoneNum_str)) {
                            MyToast.showToast("手机号码格式不正确", context);
                            return;
                        } else if (TextUtils.isEmpty(homeTel_str)) {
                            UtilToast.show(context, "家庭电话不能为空");
                            return;
                        } else if (!Validator.isZuoJi(homeTel_str)) {
                            MyToast.showToast("家庭电话 不正确", context);
                            return;
                        } else if (TextUtils.isEmpty(workTel_str)) {
                            UtilToast.show(context, "工作电话不能为空");
                            return;
                        } else if (!Validator.isZuoJi(workTel_str)) {
                            MyToast.showToast("工作电话 不正确", context);
                            return;
                        } else if (TextUtils.isEmpty(reCallFirst_str)) {
                            UtilToast.show(context, "首选回访电话不能为空");
                            return;
                        } else if (!Validator.isZuoJi(reCallFirst_str)) {
                            MyToast.showToast("首选回访电话 不正确", context);
                            return;
                        } else if (TextUtils.isEmpty(address_str)) {
                            UtilToast.show(context, "联系地址不能为空");
                            return;
                        } else if (TextUtils.isEmpty(postCode_str)) {
                            UtilToast.show(context, "邮编不能为空");
                            return;
                        } else if (!Validator.isPostCode(postCode_str)) {
                            MyToast.showToast("联系地址邮编格式不正确", context);
                            return;
                        } else if (TextUtils.isEmpty(email_str)) {
                            UtilToast.show(context, "邮箱不能为空");
                            return;
                        } else if (!Validator.isEmail(email_str)) {
                            MyToast.showToast("邮箱格式不正确", context);
                            return;
                        }

                        o.put("name", name_str);
                        o.put("sex", sex_str);
                        o.put("nationality", country_str);
                        o.put("marriage", hasWife_str);
                        o.put("papers_type", cardType_str);

                        o.put("idnum", cardNum_str);
                        o.put("birth", birthday_str);
//                        o.put("id_url", idCardUrl);
//                        o.put("self_url", peopleUrl);
                        o.put("age", age_str);

                        o.put("work_unit", workPlace_str);
                        o.put("annual_income", income_str);
                        o.put("profession", job_str);
                        o.put("cellphone", phoneNum_str);
                        o.put("telephone", homeTel_str);

                        o.put("office_phone", workTel_str);
                        o.put("first_phone", reCallFirst_str);
                        o.put("contact_addr", address_str);
                        o.put("c_postcode", postCode_str);
                        o.put("home_addr", homeAddress_str);

                        o.put("h_postcode", homePostCode_str);
                        o.put("email", email_str);

                        //图片传的是路径
                        bundle.putString("other_idUrl", picMap.get(3));
                        bundle.putString("other_peopleUrl", picMap.get(4));

                        bundle.putString("other_insureds", o.toString());

                        UtilLog.e("====other_insureds====", o.toString());


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                }


                //bundle 传值  下面几个view
                bundle.putString("relation_yuBeiBao", relation_yuBeiBao);//TODO 与被保险人关系 这个注意啊

                bundle.putString("insurance_type", insurance_type);
                bundle.putString("copies", copies);
                bundle.putString("premium", premium);
                bundle.putString("payment_way", payment_way);
                if (payment_way.equals("1")) {
                    //当缴费方式为分期的时候 有下面两个参数
                    bundle.putString("payment_is", payment_is);
                }
                bundle.putString("time_limit", time_limit);//这是保险持续时间
                bundle.putString("starttime", starttime);

                //这个json 是投保人信息 applicant_information
                JSONArray jsonArray = new JSONArray();
                JSONObject jsonObject = new JSONObject();
                try {

                    if (TextUtils.isEmpty(starttime)) {
                        UtilToast.show(context, "起保时间不能为空");
                        return;
                    } else if (TextUtils.isEmpty(picMap.get(1))) {
                        UtilToast.show(context, "请上传投保人身份证照片");
                        return;
                    } else if (TextUtils.isEmpty(name)) {
                        UtilToast.show(context, "投保人姓名不能为空");
                        return;
                    } else if (TextUtils.isEmpty(touBaoRenSex)) {
                        UtilToast.show(context, "性别不能为空");
                        return;
                    } else if (TextUtils.isEmpty(nationality)) {
                        UtilToast.show(context, "国籍不能为空");
                        return;
                    } else if (TextUtils.isEmpty(age)) {
                        UtilToast.show(context, "年龄不能为空");
                        return;
                    } else if (TextUtils.isEmpty(birth)) {
                        UtilToast.show(context, "出生日期不能为空");
                        return;
                    } else if (TextUtils.isEmpty(papers_type)) {
                        UtilToast.show(context, "请选择证件类型");
                        return;
                    } else if (TextUtils.isEmpty(idnum)) {
                        UtilToast.show(context, "证件号码不能为空");
                        return;
                    } else if (!Validator.isIDCard(idnum)) {
                        MyToast.showToast("证件号码不正确", context);
                        return;
                    } else if (TextUtils.isEmpty(home_addr)) {
                        UtilToast.show(context, "家庭地址不能为空");
                        return;
                    } else if (TextUtils.isEmpty(h_postcode)) {
                        UtilToast.show(context, "邮编不能为空");
                        return;
                    } else if (!Validator.isPostCode(h_postcode)) {
                        MyToast.showToast("家庭地址邮编格式不正确", context);
                        return;
                    } else if (TextUtils.isEmpty(marriage)) {
                        UtilToast.show(context, "婚姻状况不能为空");
                        return;
                    } else if (TextUtils.isEmpty(picMap.get(2))) {
                        UtilToast.show(context, "请上传投保人照片");
                        return;
                    } else if (TextUtils.isEmpty(work_unit)) {
                        UtilToast.show(context, "工作单位不能为空");
                        return;
                    } else if (TextUtils.isEmpty(annual_income)) {
                        UtilToast.show(context, "年收入不能为空");
                        return;
                    } else if (TextUtils.isEmpty(profession)) {
                        UtilToast.show(context, "请选择职业");
                        return;
                    } else if (TextUtils.isEmpty(cellphone)) {
                        UtilToast.show(context, "手机号码不能为空");
                        return;
                    } else if (!Validator.isMobile(cellphone)) {
                        MyToast.showToast("手机号码格式不正确", context);
                        return;
                    } else if (TextUtils.isEmpty(telephone)) {
                        UtilToast.show(context, "家庭电话不能为空");
                        return;
                    } else if (!Validator.isZuoJi(telephone)) {
                        MyToast.showToast("家庭电话 不正确", context);
                        return;
                    } else if (TextUtils.isEmpty(office_phone)) {
                        UtilToast.show(context, "工作电话不能为空");
                        return;
                    } else if (!Validator.isZuoJi(office_phone)) {
                        MyToast.showToast("工作电话 不正确", context);
                        return;
                    } else if (TextUtils.isEmpty(first_phone)) {
                        UtilToast.show(context, "首选回访电话不能为空");
                        return;
                    } else if (!Validator.isZuoJi(first_phone)) {
                        MyToast.showToast("首选回访电话 不正确", context);
                        return;
                    } else if (TextUtils.isEmpty(contact_addr)) {
                        UtilToast.show(context, "联系地址不能为空");
                        return;
                    } else if (TextUtils.isEmpty(c_postcode)) {
                        UtilToast.show(context, "邮编不能为空");
                        return;
                    } else if (!Validator.isPostCode(c_postcode)) {
                        MyToast.showToast("联系地址邮编格式不正确", context);
                        return;
                    } else if (TextUtils.isEmpty(email)) {
                        UtilToast.show(context, "邮箱不能为空");
                        return;
                    } else if (!Validator.isEmail(email)) {
                        MyToast.showToast("邮箱格式不正确", context);
                        return;
                    }

                    jsonObject.put("name", name);
                    jsonObject.put("sex", touBaoRenSex);
                    jsonObject.put("nationality", nationality);
                    jsonObject.put("marriage", marriage);
                    jsonObject.put("papers_type", papers_type);

                    jsonObject.put("idnum", idnum);
                    jsonObject.put("birth", birth);
//                    jsonObject.put("id_url", id_url);
//                    jsonObject.put("self_url", self_url);
                    jsonObject.put("age", age);

                    jsonObject.put("work_unit", work_unit);
                    jsonObject.put("annual_income", annual_income);
                    jsonObject.put("profession", profession);
                    jsonObject.put("cellphone", cellphone);
                    jsonObject.put("telephone", telephone);

                    jsonObject.put("office_phone", office_phone);
                    jsonObject.put("first_phone", first_phone);
                    jsonObject.put("contact_addr", contact_addr);
                    jsonObject.put("c_postcode", c_postcode);
                    jsonObject.put("home_addr", home_addr);

                    jsonObject.put("h_postcode", h_postcode);
                    jsonObject.put("email", email);
                    ////////////////////下面是受益人信息 death_beneficiary///////////////////////

                    for (int i = 0; i < holderMap.size(); i++) {

                        JSONObject jsonObject1 = new JSONObject();

                        if (i == 0) {

                            if (TextUtils.isEmpty(name_shouYiRen)) {
                                UtilToast.show(context, "身故保险金受益人不能为空");
                                return;
                            } else if (TextUtils.isEmpty(birthday_shouYiRen)) {
                                UtilToast.show(context, "请选择    出生日期");
                                return;
                            }  else if (TextUtils.isEmpty(relation)) {
                                UtilToast.show(context, "请选择    是被保险人的");
                                return;
                            } else if (TextUtils.isEmpty(papers_type_shouYiRen)) {
                                UtilToast.show(context, "请选择受益人证件类型");
                                return;
                            } else if (TextUtils.isEmpty(number)) {
                                UtilToast.show(context, "受益人证件号码不能为空");
                                return;
                            } else if (!Validator.isIDCard(number)) {
                                MyToast.showToast("身份证号码不正确", context);
                                return;
                            } else if (TextUtils.isEmpty(benefit_ratio)) {
                                UtilToast.show(context, "受益比率不能为空");
                                return;
                            }

                            if (!(Float.valueOf(benefit_ratio) > 0 || Float.valueOf(benefit_ratio) <= 100)) {
                                MyToast.showToast("请输入 大于0 小于等于100 的数字", context);
                                return;
                            }
                            jsonObject1.put("name", name_shouYiRen);
                            jsonObject1.put("birth", birthday_shouYiRen);
                            jsonObject1.put("sex", sex);
                            jsonObject1.put("relation", relation);
                            jsonObject1.put("papers_type", papers_type_shouYiRen);
                            jsonObject1.put("number", number);
                            jsonObject1.put("benefit_ratio", benefit_ratio);
                            jsonObject1.put("benefit_order", benefit_order);
                        } else {

                            String nameStr_newView = ((EditText) holderMap.get(i + "").findViewById(R.id.shouYiRenName_ywx)).getText().toString();
                            String birthStr_newView = ((TextView) holderMap.get(i + "").findViewById(R.id.shouYiRenBirthday_ywx)).getText().toString();
                            String cardNumStr_newView = ((EditText) holderMap.get(i + "").findViewById(R.id.shouYiRenidCardNum_ywx)).getText().toString();
                            String biLvStr_newView = ((EditText) holderMap.get(i + "").findViewById(R.id.shouYiBiLv_ywx)).getText().toString();
                            String shunXuStr_newView = ((TextView) holderMap.get(i + "").findViewById(R.id.shouYiShunXu_ywx)).getText().toString();
                            String shiBeiBaoRenDeStr_newView = ((TextView) holderMap.get(i + "").findViewById(R.id.shiBeiBaoRenDe_ywx)).getText().toString();
                            String cardTypeStr_newView = ((TextView) holderMap.get(i + "").findViewById(R.id.shouYiRenCardtype_ywx)).getText().toString();
                            String sex_newView;
                            if ((boolean) ((holderMap.get(i + "").findViewById(R.id.manImg_ywx)).getTag())) {
                                sex_newView = "男";
                            } else {
                                sex_newView = "女";
                            }

                            if (TextUtils.isEmpty(nameStr_newView)) {
                                UtilToast.show(context, "身故保险金受益人不能为空");
                                return;
                            } else if (TextUtils.isEmpty(birthStr_newView)) {
                                UtilToast.show(context, "请选择出生日期");
                                return;
                            }  else if (TextUtils.isEmpty(shiBeiBaoRenDeStr_newView)) {
                                UtilToast.show(context, "是被保人的不能为空");
                                return;
                            } else if (TextUtils.isEmpty(cardTypeStr_newView)) {
                                UtilToast.show(context, "请选择受益人证件类型");
                                return;
                            } else if (TextUtils.isEmpty(cardNumStr_newView)) {
                                UtilToast.show(context, "受益人证件号码不能为空");
                                return;
                            } else if (!Validator.isIDCard(cardNumStr_newView)) {
                                MyToast.showToast("身份证号码不正确", context);
                                return;
                            } else if (TextUtils.isEmpty(biLvStr_newView)) {
                                UtilToast.show(context, "受益比率不能为空");
                                return;
                            }
                            //判断比率是否正确
                            if (!(Float.valueOf(biLvStr_newView) > 0 || Float.valueOf(biLvStr_newView) <= 100)) {
                                MyToast.showToast("请输入  大于0小于等于100  的数字", context);
                                return;
                            }


                            jsonObject1.put("name", nameStr_newView);
                            jsonObject1.put("birth", birthStr_newView);
                            jsonObject1.put("sex", sex_newView);
                            jsonObject1.put("relation", shiBeiBaoRenDeStr_newView);
                            jsonObject1.put("papers_type", cardTypeStr_newView);
                            jsonObject1.put("number", cardNumStr_newView);
                            jsonObject1.put("benefit_ratio", biLvStr_newView);
                            jsonObject1.put("benefit_order", shunXuStr_newView);
                        }

                        jsonArray.put(jsonObject1);

                    }

                    //bundle 传值
                    bundle.putString("applicant_information", jsonObject.toString());
                    bundle.putString("death_beneficiary", jsonArray.toString());

                    UtilLog.e("====applicant_information===", jsonObject.toString());
                    UtilLog.e("====death_beneficiary===", jsonArray.toString());

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                bundle.putString("applica_idUrl", picMap.get(1));
                bundle.putString("applica_peopleUrl", picMap.get(2));

                intent.putExtras(bundle);
                startActivity(intent);
                return;
        }


    }

    private int ii = 0;

    private void initAddedview() {

        final View newViwe = LayoutInflater.from(context).inflate(R.layout.shouyiren_view, null);
        BaseApplication.ScaleScreenHelper.loadView((ViewGroup) newViwe);
        shouYiRenLayout.addView(newViwe);
//        shouYiRenLayout.setTag(ii + "");

        manImg_newView = ((ImageView) newViwe.findViewById(R.id.manImg_ywx));
        womenImg_newView = ((ImageView) newViwe.findViewById(R.id.womenLayoutImg_ywx));


        //默认选男
        manImg_newView.setImageResource(R.mipmap.nv);
        womenImg_newView.setImageResource(R.mipmap.nan);
        manImg_newView.setTag(true);
        womenImg_newView.setTag(false);

        holderMap.put(++ii + "", newViwe);

        for (int i = 0; i < holderMap.size(); i++) {
            final int finalI = i;
            holderMap.get(i + "").findViewById(R.id.sexManLayout_ywx).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    UtilToast.show(context, "====================" + shouYiRenLayout.getTag());

                    ((ImageView) holderMap.get(finalI + "").findViewById(R.id.manImg_ywx)).setImageResource(R.mipmap.nv);
                    ((ImageView) holderMap.get(finalI + "").findViewById(R.id.womenLayoutImg_ywx)).setImageResource(R.mipmap.nan);
                    holderMap.get(finalI + "").findViewById(R.id.manImg_ywx).setTag(true);
                    holderMap.get(finalI + "").findViewById(R.id.womenLayoutImg_ywx).setTag(false);

                }
            });

            holderMap.get(i + "").findViewById(R.id.sexWomenLayout_ywx).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    UtilToast.show(context, "====================" + shouYiRenLayout.getTag());

                    ((ImageView) holderMap.get(finalI + "").findViewById(R.id.manImg_ywx)).setImageResource(R.mipmap.nan);
                    ((ImageView) holderMap.get(finalI + "").findViewById(R.id.womenLayoutImg_ywx)).setImageResource(R.mipmap.nv);
                    holderMap.get(finalI + "").findViewById(R.id.manImg_ywx).setTag(false);
                    holderMap.get(finalI + "").findViewById(R.id.womenLayoutImg_ywx).setTag(true);

                }
            });

            holderMap.get(i + "").findViewById(R.id.shiBeiBaoRenDe_ywx).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.setTag(10);
                    showPopupWindow(v, finalI);
                }
            });

            holderMap.get(i + "").findViewById(R.id.shouYiRenCardtype_ywx).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.setTag(9);
                    showPopupWindow(v, finalI);
                }
            });


            holderMap.get(i + "").findViewById(R.id.shouYiRenBirthday_ywx).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    DateTimePickDialogUtil dialogUtil = new DateTimePickDialogUtil(LifeInsuranceFillInfoActivity.this, null);
                    dialogUtil.dateTimePicKDialog((TextView) holderMap.get(finalI + "").findViewById(R.id.shouYiRenBirthday_ywx));
                }
            });


            ((TextView) holderMap.get(i + "").findViewById(R.id.shouYiShunXu_ywx)).setText(i + 1 + "");

            ((EditText) holderMap.get(i + "").findViewById(R.id.shouYiRenName_ywx)).addTextChangedListener(new MEditTextListener(context, 16, (EditText) holderMap.get(i + "").findViewById(R.id.shouYiRenName_ywx)));
            ((EditText) holderMap.get(i + "").findViewById(R.id.shouYiRenidCardNum_ywx)).addTextChangedListener(new MEditTextListener(context, 18, (EditText) holderMap.get(i + "").findViewById(R.id.shouYiRenidCardNum_ywx)));
            ((EditText) holderMap.get(i + "").findViewById(R.id.shouYiBiLv_ywx)).addTextChangedListener(new MEditTextListener(context, 5, (EditText) holderMap.get(i + "").findViewById(R.id.shouYiBiLv_ywx)));

        }

    }


    private void showPopupWindow(View view, final int i) {

        View contentView = getLayoutInflater().inflate(R.layout.pop_layout, null);

        final ListView popList = (ListView) contentView.findViewById(R.id.item_popList);

        ArrayAdapter adapter = null;
        final int tag = (Integer) view.getTag();
        switch (tag) {
            case 1:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, payTypeList);
                break;

            case 2:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, relationList);
                break;

            case 3:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, relationshipList);
                break;

            case 4:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, cardTypeList);
                break;

            case 5:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, jobList);
                break;

            case 6:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, cardTypeList);
                break;

            case 7:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, cardTypeList);
                break;

            case 8:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, jobList);
                break;

            case 9:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, cardTypeList);
                break;

            case 10:
                adapter = new ArrayAdapter(context, R.layout.support_simple_spinner_dropdown_item, relationshipList);
                break;
        }

        popList.setAdapter(adapter);

        final PopupWindow popupWindow = new PopupWindow(contentView, view.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT, true);

        popupWindow.setTouchable(true);

        popupWindow.setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return false;
            }
        });

        popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_white_bg));

        popupWindow.showAsDropDown(view);

        popList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                switch (tag) {
                    case 1:
//                        payType.setText(payTypeList.get(position));
//                        payType.setTag(String.valueOf(position + 1));
                        if (position + 1 == 2) {

                            payType.setText(payTypeList.get(position));
                            payTypeValue = "1";


                            findViewById(R.id.rlayout_dunJiao_show).setVisibility(View.VISIBLE);
                            findViewById(R.id.lLayout_fenqi_show).setVisibility(View.GONE);
                        } else {

                            new AlertDialog(context, "分期缴费功能现未开通，\n敬请期待。。。") {
                                @Override
                                protected void onConfirm() {

                                }

                                @Override
                                protected void onCancle() {

                                }
                            }.show();

//                            findViewById(R.id.rlayout_dunJiao_show).setVisibility(View.GONE);
//                            findViewById(R.id.lLayout_fenqi_show).setVisibility(View.VISIBLE);
                        }
                        break;

                    case 2:
                        yuBeiBaoRen.setText(relationList.get(position));
                        yuBeiBaoRen.setTag(String.valueOf(position + 1));

                        if (position + 1 == 1) {
                            findViewById(R.id.lLayout_otherInfo).setVisibility(View.GONE);
                        } else {
                            findViewById(R.id.lLayout_otherInfo).setVisibility(View.VISIBLE);
                        }
                        break;

                    case 3:
                        shiBeiBaoRenDe.setText(relationshipList.get(position));
                        break;

                    case 4:
                        cardType.setText(cardTypeList.get(position));
                        break;

                    case 5:
                        job.setText(jobList.get(position));
                        break;

                    case 6:
                        shouYiRenCardType.setText(cardTypeList.get(position));
                        break;

                    case 7:
                        cardType_other.setText(cardTypeList.get(position));
                        break;

                    case 8:
                        job_other.setText(jobList.get(position));
                        break;

                    case 9:
                        ((TextView) holderMap.get(i + "").findViewById(R.id.shouYiRenCardtype_ywx)).setText(cardTypeList.get(position));
                        break;

                    case 10:
                        ((TextView) holderMap.get(i + "").findViewById(R.id.shiBeiBaoRenDe_ywx)).setText(relationshipList.get(position));
                        break;
                }

                popupWindow.dismiss();
            }
        });
    }


    public String bitmaptoString(Bitmap bitmap) {


        // 将Bitmap转换成字符串

        String string = null;

        ByteArrayOutputStream bStream = new ByteArrayOutputStream();

        bitmap.compress(Bitmap.CompressFormat.JPEG, 50, bStream);

        byte[] bytes = bStream.toByteArray();
        Base64Encoder base = new Base64Encoder();
        string = base.encode(bytes); //

        //  string = Base64.encodeToString(bytes, Base64.DEFAULT);

        return string;

    }

    @Override
    protected void resultPhotoPath(ImageView imageView, String s) {


        String str = bitmaptoString(PictureUtil.getSmallBitmap(s));

        String uid = BaseApplication.BasePreferences.readUserId();

        String time = System.currentTimeMillis() + "";

        String lock = UtilMD5.MD5Encode(UtilMD5.MD5Encode(uid + time, "UTF-8") + "zhang", "UTF-8");


        //标记 已上传
        switch (i) {
            case 1:

                life_show_idcard_iv.setVisibility(View.VISIBLE);
                life_show_idcard_iv.setImageBitmap(PictureUtil.getSmallBitmap(s));

                postIDCard.userid = uid;
                postIDCard.time = time;
                postIDCard.lock = lock;
                postIDCard.base = str;

                postIDCard.execute(this);

                ((Button) findViewById(R.id.idCard_submit_ywx)).setText("已选择");
//                ((Button) findViewById(R.id.idCard_submit_ywx)).setTextColor(getResources().getColor(R.color.xinbao));
                break;
            case 2:

                life_show_people_iv.setVisibility(View.VISIBLE);
                life_show_people_iv.setImageBitmap(PictureUtil.getSmallBitmap(s));

                ((Button) findViewById(R.id.peoplePicSubmit_ywx)).setText("已选择");
//                ((Button) findViewById(R.id.peoplePicSubmit_ywx)).setTextColor(getResources().getColor(R.color.xinbao));
                break;
            case 3:

                life_show_idcard_other_iv.setVisibility(View.VISIBLE);
                life_show_idcard_other_iv.setImageBitmap(PictureUtil.getSmallBitmap(s));

                postIDCard.userid = uid;
                postIDCard.time = time;
                postIDCard.lock = lock;
                postIDCard.base = str;

                postIDCard.execute(this, 1);

                ((Button) findViewById(R.id.idCard_submit_ywx2)).setText("已选择");
//                ((Button) findViewById(R.id.idCard_submit_ywx2)).setTextColor(getResources().getColor(R.color.xinbao));
                break;
            case 4:

                life_show_people_other_iv.setVisibility(View.VISIBLE);
                life_show_people_other_iv.setImageBitmap(PictureUtil.getSmallBitmap(s));


                ((Button) findViewById(R.id.peoplePicSubmit_ywx2)).setText("已选择");
//                ((Button) findViewById(R.id.peoplePicSubmit_ywx2)).setTextColor(getResources().getColor(R.color.xinbao));
                break;
        }


        picMap.put(i, s);


    }

}
